#include "GameOverView.h"

GameOverView::GameOverView(Screen *screen, Model *m, LPDIRECT3DDEVICE9 dd3d): View(screen, m, dd3d)
{
  _model = (GameOverModel*)m;
  screen = screen;
  D3DXCreateFont(_dd3dDevice, 60, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET,
                 OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH || FF_DONTCARE,
                 "Arial", &_mainMenuFont);
  D3DXCreateFont(_dd3dDevice, 40, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET,
	               OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH || FF_DONTCARE,
                 "Arial", &_subMenuFont);
  InitRects();
}

void GameOverView::InitRects(void)
{
  SetRect(&_titleRect, 100, 100, 1000, 200);
  SetRect(&_returnRect, 200, 200, 600, 300);
}

GameOverView::~GameOverView(void)
{
  _mainMenuFont->Release();
  _subMenuFont->Release();
}

void GameOverView::Draw()
{
  HRESULT res;
  if(background != NULL)
  {
    GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Draw(this->background, NULL, NULL, NULL, D3DCOLOR_XRGB(255,255,255)), "GameOverView::Draw background");
    _sprite->End();
    _sprite->Begin(D3DXSPRITE_ALPHABLEND);
  }
  if(_model->mWin)
  {
    res = _mainMenuFont->DrawTextA(NULL, _gameOverLabelText1, _gameOverLabelTextLen1, &this->_titleRect, DT_CENTER | DT_VCENTER, _gameOverTextColor);
  }
  else
  {
    res = _mainMenuFont->DrawTextA(NULL, _gameOverLabelText2, _gameOverLabelTextLen2, &this->_titleRect, DT_CENTER | DT_VCENTER, _gameOverTextColor);
  }

  res = _subMenuFont->DrawTextA(NULL, _menuReturnOption, _menuReturnLen, &this->_returnRect , DT_LEFT | DT_VCENTER, _gameOverTextColor);
}

void GameOverView::HandleMessage(Message *msg)
{
  delete msg;
}

void GameOverView::PreRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Begin(D3DXSPRITE_ALPHABLEND), "View::PreRender Sprite::Begin");
}

void GameOverView::PostRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->End(), "View::PostRender Sprite::End");
}
